package com.ross.mode;

import java.io.*;

/**
 * @version 1.0.0
 * @className: Student
 * @description:
 * @author: zhangjunfa
 * @date: 2023/4/3 14:41
 */
public class Student implements Serializable {
    private String id;
    private String name;
    private ClassInfo classInfo;

    public Student() {
    }

    public Student(String id, String name, ClassInfo classInfo) {
        this.id = id;
        this.name = name;
        this.classInfo = classInfo;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public ClassInfo getClassInfo() {
        return classInfo;
    }

    public void setClassInfo(ClassInfo classInfo) {
        this.classInfo = classInfo;
    }

    //使用序列化技术实现深克隆
    public Object deepClone() throws IOException, ClassNotFoundException {
        //1.创建一个字节数组输出流
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        //2.用对象输入流包装
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        //3.将调用该方法的对象写出
        oos.writeObject(this);

        //4.创建一个字节数组输入流，读取刚刚输出到字节数组的对象this
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
        //5.用对象输入流包装
        ObjectInputStream ois = new ObjectInputStream(bis);
        //6.返回深克隆对象
        return (Student) ois.readObject();
    }
}
